#include<iostream>
using namespace std;
template <class T>void BubbleSort(T r[],int n);
template <class T>void ImproBubbleSort(T r[],int n);
template <class T>int length(T &arr);
template <class T>void print(T &arr);
int main()
{
    int a[]={6,4,2,7,61,4,2,72,4,2,7,6,4,2,75};
    BubbleSort(a,length(a));
    print(a);
};
//r为待排序元素所在数组；n为待排序元素个数
template <class T>void BubbleSort(T r[],int n)
{
    T change;
    for (int  i = 1; i < n; i++)
    {
        for (int j = 0; j <= n-i; j++)
        {
            if (r[j]>r[j+1])
            {
                change=r[j];
                r[j]=r[j+1];
                r[j+1]=change;
            }
        }
    }
}
//计算数组长度
template <class T>int length(T &arr)
{
    return sizeof(arr)/sizeof(arr[0]);
}
//打印数组元素
template <class T>void print(T &arr)
{
    for (int i = 0; i < length(arr); i++)
    {
        cout<<arr[i]<<" ";
    }
    cout<<endl;
}
//改进的起泡排序法
template <class T>void ImproBubbleSort(T r[],int n)
{
    int pos=n;
    T change=r[0];
    while (pos!=0)
    {
        int bound=pos;
        pos=0;
        for (int i = 0; i < bound; i++)
        {
            if (r[i]>r[i+1])
            {
                change=r[i];
                r[i]=r[i+1];
                r[i+1]=change;
            }
        }
    }
}